import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama";
import { Chroma } from "@langchain/community/vectorstores/chroma";

const embeddings = new OllamaEmbeddings({
  model: "nomic-embed-text", // default value
  baseUrl: "http://117.72.38.226:11434", // default value
  requestOptions: {
    // useMMap: true,
    numThread: 6,
    // numGpu: 1,
  },
});

const documents = ["Hello World!", "Bye Bye"];

// const documentEmbeddings = await embeddings.embedDocuments(documents);
// console.log(documentEmbeddings);


// const vectorStore = await Chroma.fromDocuments(documents, embeddings, {
//     collectionName: "test-hcy-1", // id  14486ba6-2d74-4658-a3f0-0a48a7e3455d
//     url: "http://117.72.38.226:8000", // Optional, will default to this value
//   });
// const response = await vectorStore.similaritySearch("hello", 1);

// const vectorStore = await Chroma.fromTexts(
//     [
//       `Tortoise: Labyrinth? Labyrinth? Could it Are we in the notorious Little
//           Harmonic Labyrinth of the dreaded Majotaur?`,
//       "Achilles: Yiikes! What is that?",
//       `Tortoise: They say-although I person never believed it myself-that an I
//           Majotaur has created a tiny labyrinth sits in a pit in the middle of
//           it, waiting innocent victims to get lost in its fears complexity.
//           Then, when they wander and dazed into the center, he laughs and
//           laughs at them-so hard, that he laughs them to death!`,
//       "Achilles: Oh, no!",
//       "Tortoise: But it's only a myth. Courage, Achilles.",
//     ],
//     [{ id: 2 }, { id: 1 }, { id: 3 }],
//     embeddings,
//     {
//       collectionName: "test-hcy-2", // id 45e3af77-1727-4758-b0fb-3893c20f044e
//       url: "http://117.72.38.226:8000",
//     }
//   );
  
//   const response = await vectorStore.similaritySearch("Tortoise", 2);

const vectorStore = await Chroma.fromExistingCollection(
    embeddings,
    {
        collectionName: "test-hcy-2",
        url: "http://117.72.38.226:8000",
    }
  );
  
  const response = await vectorStore.similaritySearch("Tortoise", 2);
  console.log(response);
